//
//  HKMainVC-UI.swift
//  HoneyKeyboard
//
//  Created by Wade on 2025/1/21.
//

import Foundation
import UIKit
import SnapKit
import QMUIKit
extension HKMainVC{
    
    func setupSubViews(){
        let contentView = UIView()
        self.view.addSubview(contentView)
        contentView.backgroundColor = .clear
        contentView.snp.makeConstraints { make in
            make.edges.equalTo(self.view)
//            make.top.equalTo(self.view.snp_topMargin)
        }
       
        let scrollview = UIScrollView()
        scrollview.showsVerticalScrollIndicator = false
        contentView.addSubview(scrollview)
        scrollview.snp.makeConstraints { make in
            make.left.right.bottom.equalTo(contentView)
            make.top.equalTo(contentView.safeAreaLayoutGuide.snp.top).offset(30)
        }
        
        let scrollContentView = UIView()
        scrollview.addSubview(scrollContentView)
        let height = self.view.bounds.height > 1800 ? self.view.bounds.height : 1800
        scrollContentView.snp.makeConstraints { make in
            make.edges.equalTo(scrollview)
            make.top.equalTo(scrollview.snp_topMargin).offset(100)
            make.width.equalTo(self.view.qmui_width)
            make.height.equalTo(height)
        }
        self.scrollView = scrollview
        
        scrollContentView.backgroundColor  = .clear
        scrollview.setContentOffset(CGPoint.zero, animated: true)
        
        let header = UIView()
        contentView.addSubview(header)
        header.snp.makeConstraints { make in
            make.top.equalTo(contentView.safeAreaLayoutGuide.snp.top).offset(-10)
            make.right.equalTo(contentView).offset(-20)
            make.left.equalTo(contentView).offset(20)
            make.height.equalTo(40)
        }
        header.backgroundColor = .clear
        header.clipsToBounds = true
        
        // 设置header
        let nextBtn = UIButton();
        nextBtn.setTitle("查看教程", for: .normal)
        nextBtn.titleLabel?.font = .systemFont(ofSize: 12)
        nextBtn.setTitleColor(.darkGray, for: .normal)
        nextBtn.setTitleColor(.black, for: .highlighted)
//        nextBtn.imageView.image = .init(named: "mine_header_tipmark_20x16_")
//        nextBtn.leftImageView.image = .init(named: "kb_login_close_12x12_")
        nextBtn.setImage(.init(named: "mine_header_tipmark_20x16_"), for: .normal)
        header.addSubview(nextBtn)
        nextBtn.snp.makeConstraints { make in
            make.centerY.equalTo(header)
            make.left.equalTo(header)
            make.width.equalTo(100)
            make.height.equalTo(24)
        }
        
        let vipBtn = UIButton();
       
//        nextBtn.imageView.image = .init(named: "mine_header_tipmark_20x16_")
//        nextBtn.leftImageView.image = .init(named: "kb_login_close_12x12_")
        vipBtn.setImage(.init(named: "person_mark_vipicon_80x24_"), for: .normal)
        header.addSubview(vipBtn)
        vipBtn.snp.makeConstraints { make in
            make.centerY.equalTo(header)
            make.right.equalTo(header)
            make.width.equalTo(100)
            make.height.equalTo(30)
        }
        
        let heartView = UIView()
        heartView.backgroundColor = .clear
        scrollContentView.addSubview(heartView)
        heartView.snp.makeConstraints { make in
            make.left.right.equalTo(scrollContentView)
            make.top.equalTo(scrollContentView.snp.top).offset(50)
            make.height.equalTo(350)
        }
        
        let qinmiBtn = UIButton()
        heartView.addSubview(qinmiBtn)
        qinmiBtn.setTitle("聊天亲密度", for: .normal)
        qinmiBtn.setTitleColor(.darkGray, for: .normal)
        qinmiBtn.titleLabel?.font = .systemFont(ofSize: 15)
        qinmiBtn.titleLabel?.textAlignment = .center
        heartView.addSubview(qinmiBtn)
        qinmiBtn.snp.makeConstraints { make in
            make.centerX.equalTo(heartView)
            make.width.equalTo(200)
            make.height.equalTo(30)
            make.top.equalTo(heartView)
        }
        
        
        let heartBtn = UIButton()
        heartView.addSubview(heartBtn)
        heartBtn.setBackgroundImage(.init(named: "kb_unpaid_mid_252x80_"), for: .normal)
        heartBtn.setTitle("20%", for: .normal)
        heartBtn.titleLabel?.font = .boldSystemFont(ofSize: 50)
        heartBtn.snp.makeConstraints { make in
            make.left.right.equalTo(heartView)
            make.height.equalTo(100)
            make.top.equalTo(qinmiBtn.snp.bottom).offset(20)
        }
        
        let setQinmiBtn = UIButton()
        heartView.addSubview(setQinmiBtn)
        setQinmiBtn.setTitle("设置亲密度", for: .normal)
        setQinmiBtn.setTitleColor(.systemPink, for: .normal)
        setQinmiBtn.titleLabel?.font = .systemFont(ofSize: 15)
        setQinmiBtn.titleLabel?.textAlignment = .center
        setQinmiBtn.snp.makeConstraints { make in
            make.centerX.equalTo(heartView)
            make.width.equalTo(200)
            make.height.equalTo(30)
            make.top.equalTo(heartBtn.snp.bottom).offset(50)
        }
        
        let startBtn = UIButton()
        heartView.addSubview(startBtn)
        startBtn.setTitle("启用honey键盘", for: .normal)
        startBtn.setTitleColor(.darkGray, for: .normal)
        startBtn.titleLabel?.font = .systemFont(ofSize: 20)
        startBtn.setBackgroundImage(.init(named: "loginbtn_bg_328x56_"), for: .normal)
        startBtn.titleLabel?.textAlignment = .center
        heartView.addSubview(startBtn)
        startBtn.snp.makeConstraints { make in
            make.centerX.equalTo(heartView)
            make.width.equalTo(328)
            make.height.equalTo(56)
            make.top.equalTo(setQinmiBtn.snp.bottom).offset(30)
        }
        
        
        let markitView = UIView()
        markitView.backgroundColor = .clear
        scrollContentView.addSubview(markitView)
        markitView.snp.makeConstraints { make in
            make.left.right.equalTo(scrollContentView)
            make.top.equalTo(heartView.snp.bottom).offset(10)
            make.height.equalTo(80)
        }
        
        let item1 = UIView();
        markitView.addSubview(item1)
        item1.backgroundColor = UIColor(red: 0.5, green: 0.5, blue: 0.2, alpha: 0.3)
        item1.layer.cornerRadius = 10;
        item1.clipsToBounds = true
        let itemWidth = (self.view.qmui_width - 60)/2
        let itemHeight = 80;
        item1.snp.makeConstraints { make in
            make.width.equalTo(itemWidth)
            make.height.equalTo(itemHeight)
            make.left.equalTo(markitView).offset(20)
            make.top.equalTo(markitView)
        }
        
        let itemLabel1 = UILabel()
        item1.addSubview(itemLabel1)
        itemLabel1.text = "聊天人设时长"
        itemLabel1.font = .systemFont(ofSize: 14)
        itemLabel1.textColor = .black
        itemLabel1.textAlignment = .left
        itemLabel1.snp.makeConstraints { make in
            make.left.equalTo(item1).offset(10)
            make.top.equalTo(item1).offset(15)
            make.height.equalTo(30)
            make.width.equalTo(150)
        }
        
        let itemLabel11 = UILabel()
        item1.addSubview(itemLabel11)
        itemLabel11.text = "添加更多人设"
        itemLabel11.font = .systemFont(ofSize: 12)
        itemLabel11.textColor = .darkGray
        itemLabel11.textAlignment = .left
        itemLabel11.snp.makeConstraints { make in
            make.left.equalTo(item1).offset(10)
            make.top.equalTo(itemLabel1.snp.bottom).offset(0)
            make.height.equalTo(30)
            make.width.equalTo(150)
        }
        
        let itemImage = UIImageView()
        item1.addSubview(itemImage)
        itemImage.image = .init(named: "home_kb_arrow_right_16x16_")
        itemImage.snp.makeConstraints { make in
            make.width.height.equalTo(15)
            make.centerY.equalTo(itemLabel1)
            make.right.equalTo(item1).offset(-15)
        }
        
        let itemBtn1 = UIButton()
        item1.addSubview(itemBtn1)
        itemBtn1.snp.makeConstraints { make in
            make.edges.equalTo(item1)
        }
        
        
        let item2 = UIView();
        item2.backgroundColor = UIColor(red: 0.8, green: 0.2, blue: 0.1, alpha: 0.3)
        item2.layer.cornerRadius = 10;
        item2.clipsToBounds = true
        markitView.addSubview(item2)
        item2.snp.makeConstraints { make in
            make.width.equalTo(itemWidth)
            make.height.equalTo(itemHeight)
            make.right.equalTo(markitView).offset(-20)
            make.top.equalTo(markitView)
        }
        
        let itemLabel2 = UILabel()
        item2.addSubview(itemLabel2)
        itemLabel2.text = "聊天人设时长"
        itemLabel2.font = .systemFont(ofSize: 14)
        itemLabel2.textColor = .black
        itemLabel2.textAlignment = .left
        itemLabel2.snp.makeConstraints { make in
            make.left.equalTo(item2).offset(10)
            make.top.equalTo(item2).offset(15)
            make.height.equalTo(30)
            make.width.equalTo(150)
        }
        
        let itemLabel22 = UILabel()
        item2.addSubview(itemLabel22)
        itemLabel22.text = "添加更多人设"
        itemLabel22.font = .systemFont(ofSize: 12)
        itemLabel22.textColor = .darkGray
        itemLabel22.textAlignment = .left
        itemLabel22.snp.makeConstraints { make in
            make.left.equalTo(item2).offset(10)
            make.top.equalTo(itemLabel2.snp.bottom).offset(0)
            make.height.equalTo(30)
            make.width.equalTo(150)
        }
        
        let itemImage2 = UIImageView()
        item2.addSubview(itemImage2)
        itemImage2.image = .init(named: "home_kb_arrow_right_16x16_")
        itemImage2.snp.makeConstraints { make in
            make.width.height.equalTo(15)
            make.centerY.equalTo(itemLabel2)
            make.right.equalTo(item2).offset(-15)
        }
        
        let itemBtn2 = UIButton()
        item2.addSubview(itemBtn2)
        itemBtn2.snp.makeConstraints { make in
            make.edges.equalTo(item2)
        }
        itemBtn1.addTarget(self, action: #selector(item1BtnClick), for: .touchUpInside)
        itemBtn2.addTarget(self, action: #selector(item2BtnClick), for: .touchUpInside)
        
        // 我的键盘
        let keyHeader = UIView()
        keyHeader.backgroundColor = .clear
        scrollContentView.addSubview(keyHeader)
        keyHeader.snp.makeConstraints { make in
            make.left.equalTo(scrollContentView.snp.left).offset(20)
            make.right.equalTo(scrollContentView.snp.right).offset(-20)
            make.height.equalTo(50)
            make.top.equalTo(markitView.snp.bottom).offset(20)
        }
        
        let keyTitle = UILabel()
        keyTitle.text = "我的键盘"
        keyTitle.font = .systemFont(ofSize: 18)
        keyTitle.textColor = .black
        keyTitle.textAlignment = .left
        keyHeader.addSubview(keyTitle)
        keyTitle.snp.makeConstraints { make in
            make.left.equalTo(keyHeader)
            make.width.equalTo(150)
            make.height.equalTo(keyHeader)
            make.centerX.equalTo(keyHeader)
        }
        
        let keyButton = QMUIButton(type: .custom)
        keyButton.imagePosition = .right
        keyButton.setImage(.init(named: "home_kb_arrow_right_16x16_"), for: .normal)
        keyButton.setTitle("修改键盘排序", for: .normal)
        keyButton.titleLabel?.font = .systemFont(ofSize: 12)
        keyButton.setTitleColor(.lightGray, for: .normal)
        keyHeader.addSubview(keyButton)
        keyButton.snp.makeConstraints { make in
            make.right.equalTo(keyHeader)
            make.centerY.equalTo(keyHeader)
            make.width.equalTo(90)
            make.height.equalTo(keyHeader)
        }
        keyButton.addTarget(self, action: #selector(changeKeyboardSortBtnClick), for: .touchUpInside)
    }
}
